﻿//数据加载（通用）---转换字符串函数都定义为showlist(e)
var load = function () {
    var list = function (url,page) {
        $(".loading").show();
        $.post(url, { page: page }, function (date, status) {
            if (status == "success") {
                console.log(date);
                $("#givew_body tbody").html(showlist(date));
            }
        }, "json");
    }
    return {
        show: function (url, page) {
            list(url,page);
        }
    }
}
//p页码数据，load加载地址
function showpage(p, load) {
    var page = $("#givew_page");
    if (p.PageNo == 1) {
        console.log("第一页的时候");
        page.find("#page_next").find(".pg_icon").removeClass("no");
        page.find("#page_last").find(".pg_icon").removeClass("no");
        page.find("#page_fist").find(".pg_icon").addClass("no");
        page.find("#page_prev").find(".pg_icon").addClass("no")

        page.find("#page_fist").off("click").on("click", function () {
            layer.msg("已经是第一页了");
        });
        page.find("#page_prev").off("click").on("click", function () {
            layer.msg("没有上一页了");
        });
        page.find("#page_next").off("click").on("click", function () {
            loading.show(load, p.NextPage);
            console.log("下一页");
        });
        page.find("#page_last").off("click").on("click", function () {
            loading.show(load, p.PageCount);
            console.log("最后一页");
        });
        
    } else if (p.PageNo == p.PageCount) {
        console.log("最后一页的时候");
        page.find("#page_fist").find(".pg_icon").removeClass("no");
        page.find("#page_prev").find(".pg_icon").removeClass("no");
        page.find("#page_next").find(".pg_icon").addClass("no");
        page.find("#page_last").find(".pg_icon").addClass("no");

        page.find("#page_fist").off("click").on("click", function () {
            loading.show(load, 1);
            console.log("首页");
        });
        page.find("#page_prev").off("click").on("click", function () {
            loading.show(load, p.PrevPage);
            console.log("上一页");
        });
        page.find("#page_next").off("click").on("click", function () {
            layer.msg("已经是最后一页了，没有下一页了");
            console.log("下一页");
        });
        page.find("#page_last").off("click").on("click", function () {
            layer.msg("已经是最后一页了");
            console.log("最后一页");
        });
    } else {
        console.log("其它页");
        page.find("#page_fist").find(".pg_icon").removeClass("no");
        page.find("#page_prev").find(".pg_icon").removeClass("no");
        page.find("#page_next").find(".pg_icon").removeClass("no");
        page.find("#page_last").find(".pg_icon").removeClass("no");

        page.find("#page_fist").off("click").on("click", function () {
            loading.show(load, 1);
            console.log("首页");
        });
        page.find("#page_prev").off("click").on("click", function () {
            loading.show(load, p.PrevPage);
            console.log("上一页");
        });
        page.find("#page_next").off("click").on("click", function () {
            loading.show(load, p.NextPage);
            console.log("下一页");
        });
        page.find("#page_last").off("click").on("click", function () {
            loading.show(load, p.PageCount);
            console.log("最后一页");
        });
    }
        page.find("#pg_text").val(p.PageNo);
        page.find("#max_page").text(p.PageCount);
    
}
////把json时间类型转换
//function jsonDateFormat(jsonDate) {//json日期格式转换为正常格式
//    try {//出自http://www.cnblogs.com/ahjesus 尊重作者辛苦劳动成果,转载请注明出处,谢谢!
//        var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));
//        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
//        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
//        var hours = date.getHours();
//        var minutes = date.getMinutes();
//        var seconds = date.getSeconds();
//        var milliseconds = date.getMilliseconds();
//        return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
//    } catch (ex) {//出自http://www.cnblogs.com/ahjesus 尊重作者辛苦劳动成果,转载请注明出处,谢谢!
//        return "";
//    }
//}
////时间字符串装换为json序列化
//function timetostamp(date) {
//    var stamp = Date.parse(date);
//    stamp = stamp / 1000;
//    stamp = "\/Date(" + stamp + ")\/";
//    return stamp;
//}